package cn.com.jrj.app;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.SchedulerException;
import org.quartz.impl.StdScheduler;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.backportconcurrent.ThreadPoolTaskExecutor;

import cn.com.jrj.base.VnetAppContext;

public class PublishApplication implements Application{
	final Log log = LogFactory.getLog(getClass());
	private ApplicationContext ctx;

	public PublishApplication() {
		initPublishInfo();
	}
	private void initPublishInfo() {
		VnetAppContext.configure(VnetAppContext.FROM_APPLICATION);
		ctx = VnetAppContext.getSpringCtx();
	}

	public void startup() throws Exception {
		StdScheduler stdScheduler = (StdScheduler) ctx.getBean("quartzScheduler");
		try {
			stdScheduler.start();
		} catch (SchedulerException e) {
			log.error(PublishApplication.class.getName() + "#start SchedulerException", e);
		}
	}

	public void close() {
		ThreadPoolTaskExecutor taskExecutor = (ThreadPoolTaskExecutor) ctx.getBean("taskExecutor");
		taskExecutor.shutdown();
		StdScheduler stdScheduler = (StdScheduler) ctx.getBean("quartzScheduler");
		stdScheduler.shutdown();

	}
	public static void main(String[] args) throws Exception {
		PublishApplication apps = new PublishApplication();
		apps.startup();
	}
}
